<?php
    include('include/header.inc.php');  // Nous appelons notre header
    if ($_SESSION['name'] == '')
    {
        echo '<script>location.href="detailEvent.php?event=1"</script>';
    }
?>

<div data-role="content" >	
    <h2>Web Event Management</h2>
        <?php
            if(empty($_POST['username'])||empty($_POST['password'])){
                echo '<br/>*Veuillez remplir tous les champs';
            }
            else
            {
                $username = $_POST['username'];
                $password = $_POST['password'];
                // Fichier de configuration pour l'interface PHP
                //  de notre annuaire LDAP
                $server = "153.109.141.54";
                $port = "10389";

                // El�ments d'authentification LDAP
                //$ldaprdn  = "uid=".$username.", ou=system";    // DN ou RDN LDAP
                $ldaprdn  = "cn=".$username.", ou=users, ou=system";    // DN ou RDN LDAP
                $ldappass = $password;  // Mot de passe associ�

                // Connexion au serveur LDAP
                $ldapconn = ldap_connect($server,$port)
                                or die("Impossible de se connecter au serveur LDAP.");

                if ($ldapconn) {

                    ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
                    // Connexion au serveur LDAP
                    $ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappass)
                            or die("Login ou mot de passe inconnu.");

                    $filter="cn=$username";
                    $justthese = array("ou", "sn", "givenname", "mail", "uid", "description");

                    $sr=ldap_search($ldapconn, $ldaprdn, $filter, $justthese);

                    $info = ldap_get_entries($ldapconn, $sr);

                    ?>
                    <form method='POST' action="./profil.php">
                        <h3>Mon profil</h3>
                            <?php 
                            $sn = $info[0]["sn"][0];
                            echo $texts['name'][$_SESSION['lang']]." : <input type='text' name='sn' id='sn'  maxlength='50' value='$sn'/>";

                            $givenname = $info[0]["givenname"][0];
                            echo $texts['firstname'][$_SESSION['lang']]." : <input type='text' name='givenname' id='givenname'  maxlength='50' value='$givenname'/>";
                            $_SESSION['name'] = $givenname.' '.$sn;

                            $uid = $info[0]["uid"][0];
                            $_SESSION['login'] = $uid;
                            echo $texts['username'][$_SESSION['lang']]." : <input type='text' name='uid' id='uid'  maxlength='50' value='$uid'/>";

                            $description = $info[0]["description"][0];
                            echo $texts['description'][$_SESSION['lang']]." : <input type='text' name='description' id='description'  maxlength='50' value='$description'/>";

                            $mail = $info[0]["mail"][0];
                            $_SESSION['mail']  = $mail;
                            echo $texts['email'][$_SESSION['lang']]." : <input type='text' name='mail' id='mail'  maxlength='50' value='$mail'/>"; ?>
                    </form>
                <?php
                }
            }
    ?>
    <p><a href="./index.php" data-role="button"><?php echo $texts['home'][$_SESSION['lang']] ?></a></p>
</div>
    <?php
        include('include/footer.inc.php');  // Nous appelons notre menu
    ?>
</body>
</html>